<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page
	import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="com.shiplanet.service.CategoryService"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%
	ServletContext sc = this.getServletConfig().getServletContext();
	ApplicationContext ac2 = WebApplicationContextUtils
			.getWebApplicationContext(sc);
	CategoryService categoryService = (CategoryService) ac2
			.getBean("categoryService");
	request.setAttribute("categoryMap",
			categoryService.getCategoryNameMap(false, false));
%>

<section class="background-page">
	<div class="row padding-top">

		<tiles:insertAttribute name="adminmenu" />

		<article class="column custom-main-column">

			<div id="top" class="row collapse">
				<div class="column large-12">

					<div class="row">
						<div
							class="box-shadow background-white more-margin-bottom clearfix card content-padding">
							<div
								class="large-12 clearfix blue-topper heading-padding card-header">
								<h3 class="inverse no-margin-top no-margin-bottom">
									<span class="semi-bold"><em>Post List</em></span>
								</h3>
							</div>


							<div
								class="column large-12 box-shadow background-white margin-bottom">

								<s:form action="listPost" namespace="/admin">
									<br/>
									<table width="100%">
										<tr>
											<th>Id</th>
											<th>Category</th>
											<th>Equipment Name</th>
											<th>Create Time</th>
											<th>Update</th>
											<th>Delete</th>
										</tr>
										<s:iterator value="postList" var="post">
											<tr align="center">
												<td><s:property value="id" /></td>
												<td><s:property value="category.name" /></td>
												<td><s:property value="equipmentName" /></td>
												<td><s:date name="createTime" format="dd/MM/yyyy" /></td>
												<td><s:url action="updatePost" namespace="/admin"
														var="updatePostUrl">
														<s:param name="postId" value="#post.id" />
													</s:url> <s:a href="%{updatePostUrl}">Update</s:a></td>
												<td><s:url action="deletePost" namespace="/admin"
														var="deletePostUrl">
														<s:param name="postId" value="#post.id" />
													</s:url> <s:a href="%{deletePostUrl}">Delete</s:a></td>
											</tr>
										</s:iterator>
									</table>
									<br/>
									<br/>
									<table width="100%">
										<tr>
											<td align="center" ><s:if test="lastPage > 1">
													<s:url action="listPost" namespace="/admin" var="listPostUrl1">
														<s:param name="currentPage" value="1" />
													</s:url>
													<s:a href="%{listPostUrl1}">First</s:a>
													<s:if test="currentPage + 1 <= lastPage">
														<s:url action="listPost" namespace="/admin" var="listPostUrl2">
															<s:param name="currentPage" value="currentPage + 1" />
														</s:url>
														<s:a href="%{listPostUrl2}">Next</s:a>
													</s:if>
													<s:else>Next</s:else>
													<s:if test="currentPage - 1 >= 1">
														<s:url action="listPost" namespace="/admin" var="listPostUrl3">
															<s:param name="currentPage" value="currentPage - 1" />
														</s:url>
														<s:a href="%{listPostUrl3}">Previous</s:a>
													</s:if>
													<s:else>Previous</s:else>
													<s:url action="listPost" namespace="/admin" var="listPostUrl4">
														<s:param name="currentPage" value="lastPage" />
													</s:url>
													<s:a href="%{listPostUrl4}">Last</s:a>
												</s:if></td>
										</tr>
									</table>
								</s:form>

							</div>
						</div>
					</div>

				</div>
			</div>

		</article>
	</div>
</section>